package com.bs.medicine.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

public final class DateHelper {
	
	public static final String DEFAULT_DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";
	private DateHelper() {
	}

	public static boolean isExpired(Date exirationTime) {
		Date currentDate = new Date();
		
		return currentDate.after(exirationTime);
	}

	

	public static String getCurrentTimeStamp(String parsePatterns[]) {
		return getTimeStamp(new Date(), parsePatterns);
	}

	public static String getTimeStamp(Date date,
			String parsePatterns[]) {
		return DateFormatUtils.format(date,
				ArrayUtils.isEmpty(parsePatterns) ? "yyyy-MM-dd HH:mm:ss"
						: parsePatterns[0]);
	}

	public static boolean isSameMonth(Date date1, Date date2) {
		return DateUtils.isSameInstant(DateUtils.truncate(date1, 2), DateUtils
				.truncate(date2, 2));
	}

	public static Date getNextYear(String years) {
		return DateUtils.addYears(new Date(), Integer.parseInt(years));
	}

	public static Date getFutureTime() {
		Date result = null;
		try {
			result = DateUtils.parseDate("2099-12-31 23:59:59",
					new String[] { "yyyy-MM-dd HH:mm:ss" });
		} catch (ParseException parseexception) {
		}
		return result;
	}

	public static Date string2Date(String str) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		System.out.println(str);
		if(str.equals(null)|| str==""){}else{
		date = sdf.parse(str);
		System.out.println(date);}
		return date;
	}
	public static void main(String args[]) throws ParseException {
//		System.out.println(DateUtils.parseDate("2099-12-31 23:59:50",
//				new String[] { "yyyy-MM-dd HH:mm:ss" }).after(
//				DateUtils.parseDate("2099-12-31 23:59:52",
//						new String[] { "yyyy-MM-dd HH:mm:ss" })));
		System.out.println(Calendar.getInstance());
		String str = getTimeStamp(Calendar.getInstance().getTime(),new String[] { "yyyy-MM-dd HH:mm:ss" });
		System.out.println(str);
		SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		


		Date date =DateUtils.parseDate(str,new String[] { "yyyy-MM-dd HH:mm:ss" });
		System.out.println(myFmt2.format(date));
		System.out.println(date);
	}

	
}
